from rest_framework.response import Response
from rest_framework.views import APIView

from xyz.models import Recruit
from xyz.serializers.recruit import RecruitSerializer


class RecruitAPIView(APIView):

    def post(self, request):

        # 城市
        city = self.request.data.get('cityname')
        # 职位
        keyword = self.request.data.get('keyword')

        recruits = Recruit.objects.filter(city=city, jobname__icontains=keyword)

        recruit_list = []

        for recruit in recruits:

            serializer = RecruitSerializer(recruit)

            recruit_list.append(serializer.data)


        return Response(recruit_list)

